#include "dma.h"

void dma_init(uint32_t *src,uint32_t *drc,uint32_t size)
{
	DMA_InitTypeDef DMA_InitStruct;
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);
	DMA_InitStruct.DMA_BufferSize=size;//搬运数据大小
	DMA_InitStruct.DMA_Channel=DMA_Channel_0;//通道
	DMA_InitStruct.DMA_DIR=DMA_DIR_MemoryToMemory;//存储到存储
	
	DMA_InitStruct.DMA_FIFOMode=DISABLE;//直接模式
	DMA_InitStruct.DMA_Memory0BaseAddr=(uint32_t)drc;
	DMA_InitStruct.DMA_MemoryBurst=DMA_MemoryBurst_Single;//单次传输
	DMA_InitStruct.DMA_MemoryDataSize=DMA_MemoryDataSize_Word;//全字
	DMA_InitStruct.DMA_MemoryInc=DMA_MemoryInc_Enable;//地址++
	DMA_InitStruct.DMA_Mode=DMA_Mode_Normal;//普通模式
	
	DMA_InitStruct.DMA_PeripheralBaseAddr=(uint32_t)src;//目的地址
	DMA_InitStruct.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;//单次
	DMA_InitStruct.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Word;
	DMA_InitStruct.DMA_PeripheralInc=DMA_PeripheralInc_Enable;//地址
	DMA_InitStruct.DMA_Priority=DMA_Priority_High;//优先级
	DMA_Init(DMA2_Stream0,&DMA_InitStruct);//初始化DMA2，是配置生效
	DMA_Cmd( DMA2_Stream0, ENABLE);//开启功能
}

extern uint32_t data_src[10];
extern uint32_t data_drc[10];
void dma_compare(void)
{
	int i;
	for(i=0;i<10;i++)
	{
		if(data_drc[i]!=data_src[i])
		{
			printf("data_error[%d]:0x%x\r\n",i,data_drc[i]);
		}
		printf("data_drc[%d]:0x%x\r\n",i,data_drc[i]);
	}
}




